package gm

import (
	"ChatServerDemo/server/user"
	"ChatServerDemo/server/utils"
	"strings"
	"time"
)

func Parser(cmd string) []string {
	return strings.Split(cmd, " ")
}

func ExecStats(ctx map[string]*user.User, cmd string, nick string) string {
	u, exist := ctx[nick]
	if exist {
		t := time.Now().Unix() - u.JoinTime
		return utils.TimeFormat(t)
	}
	return ""
}

func ExecPopular(ctx map[string][]int64, cmd string, seccond int64) string {
	p:=""
	count := int64(0)
	now := time.Now().Unix()
	for k,v := range ctx {
		if len(v) == 2 {
			t := now - v[0]
			if t >= seccond {
				continue
			}
			if v[1] > count {
				//频率大
				p = k
				count = v[1]
			}
		}
	}
	return p
}